package com.ruoyi.mq;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@Configuration
public class QueueConfig {
    @Autowired
    private RedisConnectionFactory connectionFactory;
    @Autowired
    private QueueMessageListener redisMessageListener; // 自动注入监听器中的消息监听器适配器bean

    @Bean
    public RedisMessageListenerContainer container() {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.addMessageListener(redisMessageListener, thirdTopic()); // 添加监听器到容器中
        return container;  // 注意：这将自动启动容器，无需手动启动。
    }

    @Bean
    public ChannelTopic thirdTopic() {
        return new ChannelTopic(QueueSender.THIRD_QUEUE);
    }

}
